package com.four.basicinfo.controller;

import com.four.basicinfo.code.ResponseData;
import com.four.basicinfo.dao.ParentsDao;
import com.four.basicinfo.entity.Information;
import com.four.basicinfo.entity.Parents;
import com.four.basicinfo.service.ParentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/parents")
@CrossOrigin
public class ParentsController extends BaseController{
    @Autowired
    ParentsService parentsService;
    @Autowired
    ParentsDao parentsDao;

    /**
     * 获取基本信息详细信息
     */
    @GetMapping("/selectById")
    public Parents getInfo(Long id)
    {
        Parents parents=parentsDao.selectParentsById(id);
        return parents;
    }

    /**
     * 查询本人的家庭主要成员
     */
    @GetMapping("/listBynum")
    public List<Parents> list(String number){
        List<Parents> list = parentsDao.selectByNum(number);
        return list;
    }
    //选择亲戚姓名
    @GetMapping("/get")
    public List<String> selectName(String number){
        if(number==null){
            return null;
        }
        return parentsDao.selectName(number);
    }

    //根据姓名 查询 信息
    @GetMapping("/info")
    public Parents selectInfo(String name){
        if(name==null){
            return null;
        }
        return parentsDao.selectInfo(name);
    }

    //修改
    @PutMapping("/update")
    public ResponseData<Boolean> update(Parents parents){
        Boolean b = parentsService.updateParents( parents )>0;
        return returnBoolean( b );
    }

    //新增
    @PostMapping("/insert")
    public ResponseData<Boolean> insert(Parents parents){
        Boolean b = parentsService.insertParents( parents )>0;
        return returnBoolean( b );
    }
    //删除
    @DeleteMapping("/delete")
    public ResponseData<Boolean> delete(Long id){
        Boolean b=parentsService.deleteParentsById(id)>0;
        return returnBoolean( b );
    }
}
